package com.kabuda.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kabuda.blog.common.FileUpDown;
import com.kabuda.blog.dao.pojo.Article;
import com.kabuda.blog.dao.pojo.Category;
import com.kabuda.blog.mapper.CategoryMapper;
import com.kabuda.blog.service.IArticleService;
import com.kabuda.blog.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author kabuda
 * @create 2023-04-03 21:39
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private IArticleService articleService;

    private final String  folder="Category";

    @Override
    public void down(String fileName, HttpServletResponse response) {
        FileUpDown.down(fileName,response,folder);
    }

    @Override
    public String up(MultipartFile img) {
        String fileName = FileUpDown.up(img,folder);
        return fileName;
    }

    @Override
    @Transactional
    public void deleteRelation(Long categoryId) {
        this.baseMapper.deleteById(categoryId);
        articleService.deleteRelation(categoryId);
    }


}
